package com.example.it.review.acvitity.control;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.EditText;

import com.example.it.review.R;

public class EditTextActivity extends AppCompatActivity {

    private EditText etWithEnjoy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);

        etWithEnjoy = (EditText) this.findViewById(R.id.etWithEnjoy);
    }

    public void click(View view) {
        ImageSpan imageSpan = new ImageSpan(this, R.drawable.enjoy);
        SpannableString spannedString = new SpannableString("xk");
        spannedString.setSpan(imageSpan, 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        int cursor = etWithEnjoy.getSelectionStart();
        this.etWithEnjoy.getText().insert(cursor, spannedString);
    }
}
